import Vue from "vue";
import Router from "vue-router";

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

Vue.use(Router);

/* Layout */
import Layout from "@/layout";
import ParentView from "@/components/ParentView";
import InnerLink from "@/layout/components/InnerLink";

/**
 * Note: 路由配置项
 *
 * hidden: true                   // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true               // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'               // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'             // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false            // 如果设置为false，则不会在breadcrumb面包屑中显示
    affix:false,                   // 如果设置为false，则不会在 tagsviews 中显示
     activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [
  {
    path: "/redirect",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "/redirect/:path(.*)",
        component: (resolve) => require(["@/views/redirect"], resolve),
      },
    ],
  },
  {
    path: "/login",
    component: (resolve) => require(["@/views/login"], resolve),
    hidden: true,
  },
  {
    path: "/login2",
    component: (resolve) => require(["@/views/login-v2"], resolve),
    hidden: true,
  },
  // 全局前台值班数据
  {
    path: "/showTodayInfo",
    component: (resolve) => require(["@/views/front/getZhiban/index"], resolve),
    hidden: true,
  },

  {
    path: "/404",
    component: (resolve) => require(["@/views/error/404"], resolve),
    hidden: true,
  },
  {
    path: "/401",
    component: (resolve) => require(["@/views/error/401"], resolve),
    hidden: true,
  },

  {
    path: "",
    component: Layout,
    redirect: "index",
    children: [
      {
        path: "index",
        redirect: "/columnarticle/mywork", // 网站正常跳 我的工作任务
        // redirect: '/columnarticle/columnArticle',//理工大
        // component: (resolve) => require(['@/views/index'], resolve),
        name: "首页",
        hidden: true,
        meta: { title: "首页", icon: "dashboard", noCache: true, affix: false },
      },
    ],
  },

  {
    path: "/user",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "/user/profile",
        component: (resolve) =>
          require(["@/views/wycms/user/profile/index"], resolve),
        name: "Profile",
        meta: { title: "个人中心", icon: "user" },
      },
    ],
  },
];

// test=====================================================================
export const testRoute = [
  {
    path: "/word",
    component: (resolve) => require(["@/components/Word/index"], resolve),
    name: "word",
    hidden: true,
    roles: ["admin"],

    meta: { title: "word", icon: "dashboard", noCache: true, affix: false },
  },
  {
    path: "/pdf",
    component: (resolve) => require(["@/components/Pdf/index"], resolve),
    name: "pdf",
    hidden: true,
    roles: ["admin"],

    meta: { title: "pdf", icon: "dashboard", noCache: true, affix: false },
  },
  // {
  //   path: "/vextable",
  //   component: (resolve) => require(["@/test/vextable"], resolve),
  //   name: "vextable",
  //   hidden: true,
  //   roles: ["admin"],

  //   meta: { title: "vextable", icon: "dashboard", noCache: true, affix: false },
  // },
  // {
  //   path: "/vue-beauty",
  //   component: (resolve) => require(["@/test/vue-beauty"], resolve),
  //   name: "vue-beauty",
  //   hidden: true,
  //   roles: ["admin"],

  //   meta: {
  //     title: "vue-beauty",
  //     icon: "dashboard",
  //     noCache: true,
  //     affix: false,
  //   },
  // },
  // {
  //   path: "/transfer",
  //   component: (resolve) => require(["@/test/transfer"], resolve),
  //   name: "transfer",
  //   hidden: true,
  //   roles: ["admin"],

  //   meta: { title: "transfer", icon: "dashboard", noCache: true, affix: false },
  // },
  // {
  //   path: "/tree",
  //   component: (resolve) => require(["@/test/vue-giant-tree"], resolve),
  //   name: "vue-giant-tree",
  //   hidden: true,
  //   roles: ["admin"],

  //   meta: {
  //     title: "vue-giant-tree",
  //     icon: "dashboard",
  //     noCache: true,
  //     affix: false,
  //   },
  // },
  // {
  //   path: "/el-tree",
  //   component: (resolve) => require(["@/test/el-tree"], resolve),
  //   name: "el-tree",
  //   hidden: true,
  //   roles: ["admin"],

  //   meta: { title: "el-tree", icon: "dashboard", noCache: true, affix: false },
  // },
  // {
  //   path: "/editor",
  //   component: (resolve) => require(["@/test/editor"], resolve),
  //   name: "editor",
  //   hidden: true,
  //   roles: ["admin"],

  //   meta: { title: "editor", icon: "dashboard", noCache: true, affix: false },
  // },
  // {
  //   path: "/sorttable",
  //   component: (resolve) => require(["@/test/sortTable"], resolve),
  //   name: "sorttable",
  //   hidden: true,
  //   roles: ["admin"],

  //   meta: {
  //     title: "sorttable",
  //     icon: "dashboard",
  //     noCache: true,
  //     affix: false,
  //   },
  // },
  // {
  //   path: "/monaco",
  //   component: (resolve) => require(["@/test/monaco"], resolve),
  //   name: "monaco",
  //   hidden: true,
  //   roles: ["admin"],
  // },
  // {
  //   path: '/wang5',
  //   component: (resolve) => require(['@/test/wang5'], resolve),
  //   name: 'wang5',
  //   hidden: true,
  // roles: ["admin"],

  //   meta: { title: 'wang5', icon: 'dashboard', noCache: true, affix: true, }
  // },
];

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [
  // 全局文章搜索界面
  {
    path: "/articleQuery",
    component: (resolve) =>
      require(["@/views/front/articleQuery/index"], resolve),
    permissions: ["system:article:list"],
    hidden: true,
  },

  {
    path: "/dict",
    component: Layout,
    hidden: true,
    roles: ["admin"],
    permissions: ["system:dict:list"],
    children: [
      {
        path: "type/data/:dictType",
        component: (resolve) => require(["@/views/system/dict/data"], resolve),
        name: "Data",
        meta: { title: "字典数据", icon: "", activeMenu: "/system/dict" },
      },
    ],
  },
  {
    path: "/wycms/role-auth",
    component: Layout,
    hidden: true,
    permissions: ["system:role:edit"],
    children: [
      {
        path: "user/:roleId(\\d+)",
        component: () => import("@/views/wycms/role/authUser"),
        name: "AuthUser",
        meta: { title: "分配用户", activeMenu: "/wycms/role" },
      },
    ],
  },

  // 跳转新页面了 新建文章
  {
    path: "/article/addarticle",
    // roles: ["admin", "common", "Contributor", "shenhe", "fabu", "fabu-plus"],
    permissions: ["system:article:add", "system:article:edit"],
    component: (resolve) =>
      require([
        "@/views/content/columnArticle/article/components/add_editor_article",
      ], resolve),
    name: "新建文章",
    hidden: true,
    meta: { title: "新建文章", icon: "dashboard", noCache: true, affix: false },
  },
  // 跳转新页面了 新建文章库
  {
    path: "/library/addlibrary",
    // roles: ["admin", "common", "Contributor", "shenhe", "fabu", "fabu-plus"],
    permissions: ["system:library:add", "system:article:edit"],
    component: (resolve) =>
      require([
        "@/views/content/library/components/add_editor_library",
      ], resolve),
    name: "新建文章库",
    hidden: true,
    meta: { title: "新建文章", icon: "dashboard", noCache: true, affix: false },
  },
  // 跳转新页面了 新建栏目附件文章
  {
    path: "/column/appendArticle",
    // roles: ["admin", "common", "Contributor", "shenhe", "fabu", "fabu-plus"],
    permissions: ["system:channel:add"],
    component: (resolve) =>
      require([
        "@/views/content/columnArticle/column/components/appendArticle",
      ], resolve),
    name: "栏目附件文章",
    hidden: true,
    meta: {
      title: "栏目附件文章",
      icon: "dashboard",
      noCache: true,
      affix: false,
    },
  },
  // 跳转新页面了 模板编辑
  {
    path: "/template/edit",
    // roles: ['common'],
    permissions: ["system:template:edit"],
    component: (resolve) =>
      require(["@/views/template/components/edit"], resolve),
    name: "模板编辑",
    hidden: true,
    meta: { title: "模板编辑", icon: "dashboard", noCache: true, affix: false },
  },
  {
    path: "/template/view/:id",
    // roles: ["admin", "common", "Contributor", "shenhe", "fabu", "fabu-plus"],
    permissions: ["system:template:view"],
    component: (resolve) =>
      require(["@/views/template/template/view"], resolve),
    name: "模板预览",
    hidden: true,
    meta: { title: "模板预览", icon: "dashboard", noCache: true, affix: false },
  },
  // 回收站=====================================================================
  // 回收站 -新页面

  // 回收站结束=====================================================================
];

// 加载配置文件
const city_name = window.city_name;
export default new Router({
  base: city_name == "dwdt" ? "/wycms" : "/",
  mode: "history", // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes,
});
